<?php
namespace App\Services;

/**
 * 微信素材
 * @package App\Services
 */
class WxMaterialService
{
    //素材类型常量
    const TYPE_NEWS = 'news';
    const TYPE_IMAGE = 'image';
    const TYPE_VOICE = 'voice';
    const TYPE_VIDEO = 'video';
    const TYPE_THUMB = 'thumb';
    const TYPE_MUSIC = 'music';

    private $typeList;//类别列表

    /**
     * 构造函数
     */
    public function __construct()
    {
        $this->typeList = [
            self::TYPE_NEWS => __NAMESPACE__ . '\WxMaterial\WxMaterialNews',
            self::TYPE_IMAGE => __NAMESPACE__ . '\WxMaterial\WxMaterialImage',
            self::TYPE_VOICE =>__NAMESPACE__ . '\WxMaterial\WxMaterialVoice',
            self::TYPE_VIDEO => __NAMESPACE__ . '\WxMaterial\WxMaterialVideo',
            self::TYPE_THUMB => __NAMESPACE__ . '\WxMaterial\WxMaterialThumb',
            self::TYPE_MUSIC => __NAMESPACE__ . '\WxMaterial\WxMaterialMusic',
        ];
    }
    /**
     * 获取分类列表
     * @param $type
     * @return array
     */
    public function getCatList($type)
    {
        return [];
    }
    public function saveCat($request)
    {

    }
    public function delCat($catId)
    {

    }
    /**
     * 根据类别创建素材操作对象
     * @param $type
     * @return WxMaterial\wxMaterialInterface
     */
    public function createMaterial($type)
    {
        if (!array_key_exists($type, $this->typeList)){
            throw new \InvalidArgumentException("$type 无效的素材类型");
        }
        return new $this->typeList[$type];
    }

}